package com.cysyz.module.support.service;


import com.cysyz.mylib.dao.BaseDao;
import com.cysyz.mylib.dao.Conds;
import com.cysyz.mylib.dao.PagingResult;
import com.cysyz.mylib.dao.engine.PersistenceEngine;
import com.cysyz.mylib.dao.engine.Query;
import com.cysyz.mylib.dao.impl.ClassAndIdPropetryName;
import com.cysyz.mylib.dao.type.Type;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

public abstract class BaseService {
	@Resource
	private BaseDao baseRepertory;

    public void save(Object entity) {
        baseRepertory.save(entity);
    }

    public <T> PagingResult<T> listPaging(String sql, List<Object> params, Class<T> clazz, Map<String, Type> scalars, int page, int maxresult) {
        return baseRepertory.listPaging(sql, params, clazz, scalars, page, maxresult);
    }

    public <T> long getCount(Class<T> clazz, Conds conds, String queryPostfix) {
        return baseRepertory.getCount(clazz, conds, queryPostfix);
    }

    public Object getSingleResult(String ql, Map<String, Object> paramPlaceAndValues) {
        return baseRepertory.getSingleResult(ql, paramPlaceAndValues);
    }

    public int executeSql(String sql, List<Object> params) {
        return baseRepertory.executeSql(sql, params);
    }

    public <T> List<T> listCacheAble(Class<T> clazz) {
        return baseRepertory.listCacheAble(clazz);
    }

    public <T> void remove(Class<T> clazz, Serializable entityID) {
        baseRepertory.remove(clazz, entityID);
    }

    public <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds, String queryPrefix, String queryPostfix, int page, int maxresult) {
        return baseRepertory.listPaging(clazz, conds, queryPrefix, queryPostfix, page, maxresult);
    }

    public <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds, int page, int maxresult) {
        return baseRepertory.listPaging(clazz, conds, page, maxresult);
    }

    public <T> PagingResult<T> listPaging(String sql, List<Object> params, Class<T> clazz, int page, int maxresult) {
        return baseRepertory.listPaging(sql, params, clazz, page, maxresult);
    }

    public <T> List<T> listCacheAble(Class<T> clazz, String[] fieldNames, Conds conds) {
        return baseRepertory.listCacheAble(clazz, fieldNames, conds);
    }

    public PersistenceEngine getPersistenceEngine() {
        return baseRepertory.getPersistenceEngine();
    }

    public void removeByCollection(List list) {
        baseRepertory.removeByCollection(list);
    }

    public void setPersistenceEngine(PersistenceEngine persistenceEngine) {
        baseRepertory.setPersistenceEngine(persistenceEngine);
    }

    public <T> List<T> list(String sql, List<Object> params, Class<T> clazz) {
        return baseRepertory.list(sql, params, clazz);
    }

    public <T> T get(Class<T> clazz, Serializable entityID) {
        return baseRepertory.get(clazz, entityID);
    }

    public <T> List<T> list(Class<T> clazz, Conds conds) {
        return baseRepertory.list(clazz, conds);
    }

    public <T> List<T> list(Class<T> clazz, String[] fieldNames, Conds conds) {
        return baseRepertory.list(clazz, fieldNames, conds);
    }

    public <T> List<T> list(Class<T> clazz, boolean isDistinct, String[] fieldNames) {
        return baseRepertory.list(clazz, isDistinct, fieldNames);
    }

    public <T> List<T> listCacheAble(Class<T> clazz, Conds conds) {
        return baseRepertory.listCacheAble(clazz, conds);
    }

    public int execute(String ql, List<Object> params) {
        return baseRepertory.execute(ql, params);
    }

    public <T> List<T> list(Class<T> clazz, String queryPrefix) {
        return baseRepertory.list(clazz, queryPrefix);
    }

    public <T> long getCount(Class<T> clazz, Conds conds, Query queryForData) {
        return baseRepertory.getCount(clazz, conds, queryForData);
    }

    public void merge(Object entity) {
        baseRepertory.merge(entity);
    }

    public <T> List<T> listCacheAble(Class<T> clazz, boolean isDistinct, String[] fieldNames, Conds conds) {
        return baseRepertory.listCacheAble(clazz, isDistinct, fieldNames, conds);
    }

    public <T, M, K extends Serializable, N> void m2MRelationshipMapping(ClassAndIdPropetryName<T> manyClass1, Serializable manyId, ClassAndIdPropetryName<M> manyClass2, List<K> manyKeyList, Class<N> middleClass) {
        baseRepertory.m2MRelationshipMapping(manyClass1, manyId, manyClass2, manyKeyList, middleClass);
    }

    public <T> T load(Class<T> clazz, Serializable entityID) {
        return baseRepertory.load(clazz, entityID);
    }

    public <T> PagingResult<T> listPaging(Class<T> clazz, String queryPrefix, String queryPostfix, int page, int maxresult) {
        return baseRepertory.listPaging(clazz, queryPrefix, queryPostfix, page, maxresult);
    }

    public <T> List<T> list(String sql, List<Object> params, Class<T> clazz, Map<String, Type> scalars) {
        return baseRepertory.list(sql, params, clazz, scalars);
    }

    public <T> PagingResult<T> listPaging(Class<T> clazz, int page, int maxresult) {
        return baseRepertory.listPaging(clazz, page, maxresult);
    }

    public <T> long getCount(Class<T> clazz) {
        return baseRepertory.getCount(clazz);
    }

    public <T> long getCount(Class<T> clazz, Conds conds) {
        return baseRepertory.getCount(clazz, conds);
    }

    public <T> List<T> list(Class<T> clazz, boolean isDistinct, String[] fieldNames, Conds conds) {
        return baseRepertory.list(clazz, isDistinct, fieldNames, conds);
    }

    public <T> List<T> list(Class<T> clazz) {
        return baseRepertory.list(clazz);
    }

    public <T> List<T> list(Class<T> clazz, String queryPrefix, String queryPostfix) {
        return baseRepertory.list(clazz, queryPrefix, queryPostfix);
    }

    /**
	 * special entity is exist
	 * 
	 * @param clazz
	 * @param id
	 * @return
	 */
	public <T> boolean isExist(Class<T> clazz, String id) {
		Conds conds = new Conds();
		conds.addFilter(clazz.getSimpleName(), "id", id);
		return baseRepertory.getCount(clazz, conds) > 0;
	}

}
